﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace NXBSaiGon
{
    public partial class Inventory : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void Button_Click_Click(object sender, EventArgs e)
        {
            KD12.BookWS[] ls;
            KD12.WSNXBSaiGon wskd12 = new KD12.WSNXBSaiGon();
            string user = "guest";
            string pass = "Vannhungayxua_1123";
            int kt = wskd12.WSLogin(user, pass);

            if (kt != 0)
            {
                ls = wskd12.GetListBook();
                int MaSach = int.Parse(dllListItem.SelectedValue);

                foreach (KD12.BookWS book in ls)
                {
                    if (book.iMaSach == MaSach)
                    {
                        textboxSoLuongHT.Text = book.iSoLuong.ToString();
                        TextBox_GiaHT.Text = book.iDonGia.ToString();
                        Label_MaSach.Text = book.iMaSach.ToString();
                    }
                }
                
            }  
        }

        protected void Button_Refresh1_Click(object sender, EventArgs e)
        {
            KD12.BookWS[] ls;
            dllListItem.Items.Clear();

            KD12.WSNXBSaiGon wskd12 = new KD12.WSNXBSaiGon();
            string user = "guest";
            string pass = "Vannhungayxua_1123";
            int kt = wskd12.WSLogin(user, pass);
            if (kt != 0)
            {
                ls = wskd12.GetListBook();

                foreach (KD12.BookWS book in ls)
                {
                    dllListItem.Items.Add(new ListItem(book.sTenSach, book.iMaSach.ToString()));
                }
            }
        }

        protected void Button_CapNhat_Click(object sender, EventArgs e)
        {
            KD12.WSNXBSaiGon ws = new KD12.WSNXBSaiGon();
            string user = "guest";
            string pass = "Vannhungayxua_1123";
            int kt1 = ws.WSLogin(user, pass);
            int MaSach = int.Parse(dllListItem.SelectedValue);
            int DonGia = int.Parse(TextBox_GiaMoi.Text);

            int kt = ws.InventoryUpdate(MaSach, DonGia);
            Label_update.Text = kt.ToString();
            Label_Login.Text = kt1.ToString();
            
        }
    }
}